package top.yj95.xiets.basic;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

/**
 * 文章《<a href="https://blog.csdn.net/xietansheng/article/details/74363221" target="_balnk">JavaSwing_2.2: JButton（按钮）</a>》中的示例代码
 * @author 杨军
 * @since 2023-12-22
 */
public class DefaultJButtonDemo {
    
    public static void main(String[] args) {
        JFrame frame = new JFrame("测试窗口");
        frame.setSize(250, 200);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
        JPanel panel = new JPanel();
        
        // 创建一个按钮
        JButton btn = new JButton("测试按钮");
        btn.addActionListener(e -> System.out.println("按钮被点击"));
        panel.add(btn);
        
        frame.setContentPane(panel);
        frame.setVisible(true);
    }
    
}
